#include <bits/stdc++.h>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

using namespace std;

#define nullptr NULL // for some oj not supporting c++11.

int getint(int x=0)
{
    char c=getchar(); bool mi = false;
    while(c!='-' && (c<'0' || '9'<c)) c=getchar();
    if(c=='-') { mi=true; c=getchar(); }
    x=c-'0';
    while('0'<=(c=getchar()) && c<='9') x=x*10+c-'0';
    return mi ? -x : x;
}
db getdb(db x=0.0) { scanf("%lf",&x); return x; }

//========================================

const int INF = (1<<30)-1;
const int mxn = 1050;
const int mxm = 105000;

struct edge
{
    int c;
    int in;
    edge*nxt;
    edge*ptr;
}pool[mxm<<1];
edge*et;
edge*eds[mxn];
edge*cur[mxn];
edge*addedge(int i,int j,int c)
{
    et->ptr=et+1; et->in=j; et->c=c; et->nxt=eds[i]; eds[i]=et++;
    et->ptr=et-1; et->in=i; et->c=0; et->nxt=eds[j]; eds[j]=et++; 
}

int n;
int st,ed;
int dep[mxn];
int DinicDFS(int x,int mi)
{
    if(x==ed) return mi;
    int res = 0, c;
    for(edge*&i=cur[x];i;i=i->nxt)
    if(i->c>0 && dep[i->in]==dep[x]+1 && ( c=DinicDFS(i->in,min(i->c,mi)) ))
    {
        i->c -= c;
        i->ptr->c += c;
        res += c;
        mi -= c;
        if(!mi) break;
    }
    return res;
}

int q[mxn]; int qh,qt;
int Dinic()
{
    int res=0;
    while(true)
    {
        memset(dep,0xFF,sizeof(int)*(n+1));
        bool found = false;
        qh=qt=0; q[qt++]=st;
        dep[st]=0;
        while(qh!=qt && !found)
        {
            int x = q[qh++];
            for(edge*i=eds[x];i;i=i->nxt)
            if(i->c>0 && dep[i->in]==-1)
            {
                dep[i->in] = dep[x]+1;
                if(i->in==ed) { found=true; break; } 
                q[qt++] = i->in;
            }
        }
        
        if(!found) break;
        
        memcpy(cur,eds,sizeof(edge*)*(n+1));
        res += DinicDFS(st,INF);
    }
    return res;
}

int ntot,mtot;



int main()
{
    while(scanf("%d%d",&ntot,&mtot)>0)
    {
        st=ntot;
        ed=st+1;
        n=ed+1;
        
        et=pool;
        memset(eds,0,sizeof(edge*)*(n+1));
        
        int sum=0;
        
        for(int i=0;i<ntot;i++)
        {
            int c=getint();
            if(c>0) addedge(st,i,c),sum+=c;
            else if(c<0) addedge(i,ed,-c);
        }
        
        for(int i=0;i<mtot;i++)
        {
            int a,b;
            a=getint()-1;
            b=getint()-1;
            addedge(a,b,INF);
        }
        
        printf("%d\n",sum-Dinic());
        
    }
    
    return 0;
}
